-
-
Notifications
You must be signed in to change notification settings - Fork 62
Speed up CDN purges by re-using a pool manager #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AA-Turner
approved these changes
Aug 11, 2024
Co-authored-by: Adam Turner <[email protected]>
willingc
approved these changes
Sep 10, 2024
The improvement is even larger on the docs server. For Before: 57s
After: 3.5s
Adding this up, 12 languages * 3 versions * (57-3.5) seconds = ~32 minutes saved for a full build loop. 🎉 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Helps #169.
Looking at the server logs (see en-3.12.log) for building the
en/3.12
documentation, I noticed that during the publishing stage, there are 1,612 instances of purging URLs from the CDN. It does both the/3/
and/3.12/
URLs.For example, it begins:
And ends:
This takes 2 minutes and 44 seconds.
Each
purge()
command is callingrequests.request()
, which involves starting new HTTPS connections for each and every URL. The "Starting new HTTPS connection" comes from urllib3, the underlying HTTP client used by Requests.We can do better by creating a Requests "session" which will open a single connection, and re-use it by calling
session.request()
inpurge()
:https://requests.readthedocs.io/en/latest/user/advanced/
Or, because Requests is essentially wrapping the urllib3 HTTP client, we might as well use that urllib3 directly instead of Requests. The API is virtually the same.
Comparison
Re-using a connection makes it about three times quicker on my machine.
Timings from my Mac using the following test scripts.
Original
purge()
: 33 secondsWith
requests.Session()
: 11 secondsOutput is like:
With
urllib3.PoolManager()
: 10 secondsOutput is like: